package com.xq.jltx.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.xq.jltx.db.NoteDbUtils;
import com.xq.jltx.db.bean.Note;
import com.xq.jltx.greendaopro.R;
import com.xq.jltx.utils.ViewHolderUtils;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2016/07/20.
 */
public class AddNoteAdapter extends CursorAdapter{
    private Context context;
    private LayoutInflater mInflater;
    private Cursor mCursor;
    public AddNoteAdapter(Context context, Cursor c) {
        super(context, c,false);
        this.context = context;
        mCursor = c;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
        return mInflater.inflate(R.layout.add_note_item_layout,viewGroup,false);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        TextView textView1 = ViewHolderUtils.get(view,R.id.note_text1);
        TextView textView2 = ViewHolderUtils.get(view,R.id.note_text2);
        Note note = NoteDbUtils.getNoteFromCursor(cursor);
        if(note != null){
            textView1.setText(note.getText());
            textView2.setText(note.getComment());
        }
    }

}
